package com.ruoyi.system.domain.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MealStatisticsBO {
    // 餐别
    private String mealType;
    // 培训名称
    private String trainingName;
    // 订餐人数
    private Integer orderTotal = 0;
    // 区县订餐总人数
    private Integer districtOrderTotal = 0;
    // 区县订餐人数详情
    private List<DistrictDetail> details = new ArrayList<>();

    public MealStatisticsBO(String mealType, String trainingName) {
        this.mealType = mealType;
        this.trainingName = trainingName;
    }

    public void addDetail(DistrictDetail detail) {
        this.details.add(detail);
    }

    // 按区县聚合的便捷方法
    public void aggregateDetails() {
        Map<String, Integer> districtMap = new HashMap<>();
        for (DistrictDetail detail : details) {
            districtMap.merge(detail.getDistrict(), detail.getCount(), Integer::sum);
        }

        details.clear();
        districtMap.forEach((district, count) ->
                details.add(new DistrictDetail(district, count)));

        // 按人数降序排序
        details.sort((d1, d2) -> d2.getCount() - d1.getCount());
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class DistrictDetail {
        private String district;
        private Integer count;
    }
}




